package com.yang.design_patterns.singleton_design_pattern;

/**
 * @Description: 单例模式-实现之双重检测
 * @Author: 杨 强
 * @CreateTime: 2022-10-27 13:53
 */
public class DoubleDetection {
    /**
     * 唯一实例值
     */
    private static volatile DoubleDetection instance;

    /**
     * 构造私有化
     */
    public DoubleDetection() {
    }

    /**
     * 获取单例实例
     * @return 单例实例
     */
    public static DoubleDetection getInstance(){
        if (instance == null){
            synchronized (DoubleDetection.class){
                if (instance == null) {
                    instance = new DoubleDetection();
                }
            }
        }
        return instance;
    }
}
